package com.qtjf.qtmoneyservice.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;


import com.qtjf.qtmoneyservice.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2016/12/6 0006.
 */

public class AddressDialog extends Dialog {

    Context context;

    ScrollPickerView picker1;
    ScrollPickerView picker2;

    TextView okBt;
    TextView cancelBt;

    Handler handler;

   /* public SendMessageDialog(Context context){
        super(context);
        this.context = context;
    }*/

    public AddressDialog(Context context, int themeResId, Handler handler) {
        super(context, themeResId);
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.address_layout);

        picker1 = (ScrollPickerView) findViewById(R.id.picker_1);
        picker2 = (ScrollPickerView) findViewById(R.id.picker_2);

        okBt = (TextView) findViewById(R.id.ok_bt);
        cancelBt = (TextView) findViewById(R.id.cancel_bt);

        String[] st = context.getResources().getStringArray(R.array.province);
        List<String> lists1 = new ArrayList<String>(Arrays.asList(st));
        lists1.add(0,"其他");
        picker1.setData(lists1);


        okBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String str="";
                if(!(picker1.getSelectedItem().equals("其他"))&&(picker2.getSelectedItem().equals("其他")))
                {
                    str =picker1.getSelectedItem()+"省";
                }
                else if(picker1.getSelectedItem().equals("其他")&&(picker2.getSelectedItem().equals("其他")))
                {
                    str="其他";
                }else {
                    str = picker1.getSelectedItem() + " " + picker2.getSelectedItem();
                }

                Message msg=Message.obtain();
                msg.arg1=3;
                msg.obj=str;
                handler.sendMessage(msg);

                AddressDialog.this.dismiss();
            }
        });

        cancelBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              /*  Message msg=Message.obtain();
                msg.arg1=3;
                msg.obj="其他";
                handler.sendMessage(msg);*/

                AddressDialog.this.dismiss();
            }
        });


        picker1.setOnSelectedListener(new ScrollPickerView.OnSelectedListener() {
            @Override
            public void onSelected(List<String> data, int position) {
                if (data.get(position).equals("北京")) {
                    String[] st = context.getResources().getStringArray(R.array.北京);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("天津")) {
                    String[] st = context.getResources().getStringArray(R.array.天津);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("河北")) {
                    String[] st = context.getResources().getStringArray(R.array.河北);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("山西")) {
                    String[] st = context.getResources().getStringArray(R.array.山西);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("内蒙古")) {
                    String[] st = context.getResources().getStringArray(R.array.内蒙古);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("辽宁")) {
                    String[] st = context.getResources().getStringArray(R.array.辽宁);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("吉林")) {
                    String[] st = context.getResources().getStringArray(R.array.吉林);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("黑龙江")) {
                    String[] st = context.getResources().getStringArray(R.array.黑龙江);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("上海")) {
                    String[] st = context.getResources().getStringArray(R.array.上海);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("江苏")) {
                    String[] st = context.getResources().getStringArray(R.array.江苏);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("浙江")) {
                    String[] st = context.getResources().getStringArray(R.array.浙江);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("安徽")) {
                    String[] st = context.getResources().getStringArray(R.array.安徽);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("福建")) {
                    String[] st = context.getResources().getStringArray(R.array.福建);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("江西")) {
                    String[] st = context.getResources().getStringArray(R.array.江西);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("山东")) {
                    String[] st = context.getResources().getStringArray(R.array.山东);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("河南")) {
                    String[] st = context.getResources().getStringArray(R.array.河南);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("湖北")) {
                    String[] st = context.getResources().getStringArray(R.array.湖北);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("湖南")) {
                    String[] st = context.getResources().getStringArray(R.array.湖南);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("广东")) {
                    String[] st = context.getResources().getStringArray(R.array.广东);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("广西")) {
                    String[] st = context.getResources().getStringArray(R.array.广西);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("海南")) {
                    String[] st = context.getResources().getStringArray(R.array.海南);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("重庆")) {
                    String[] st = context.getResources().getStringArray(R.array.重庆);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("四川")) {
                    String[] st = context.getResources().getStringArray(R.array.四川);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("贵州")) {
                    String[] st = context.getResources().getStringArray(R.array.贵州);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("云南")) {
                    String[] st = context.getResources().getStringArray(R.array.云南);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("西藏")) {
                    String[] st = context.getResources().getStringArray(R.array.西藏);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("陕西")) {
                    String[] st = context.getResources().getStringArray(R.array.陕西);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("甘肃")) {
                    String[] st = context.getResources().getStringArray(R.array.甘肃);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("青海")) {
                    String[] st = context.getResources().getStringArray(R.array.青海);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("宁夏")) {
                    String[] st = context.getResources().getStringArray(R.array.宁夏);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("新疆")) {
                    String[] st = context.getResources().getStringArray(R.array.新疆);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("台湾")) {
                    String[] st = context.getResources().getStringArray(R.array.台湾);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("香港")) {
                    String[] st = context.getResources().getStringArray(R.array.香港);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                } else if (data.get(position).equals("澳门")) {
                    String[] st = context.getResources().getStringArray(R.array.澳门);
                    List<String> lists = new ArrayList<String>(Arrays.asList(st));
                    picker2.setData(lists);
                }else if (data.get(position).equals("其他")) {
                    List<String> lists = new ArrayList<String>();
                    lists.add("其他");
                    picker2.setData(lists);
                }


            }
        });


    }


    public void closeDialog() {
        this.dismiss();
    }

}
